<?php
/**
 *  💡 免责声明：本软件不得用于商业用途，仅做学习交流
 *  ⚠️ 权利声明：本软件由版权人提供产品技术支持
 *  📅 项目编号：NX2025-0135
 */
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateProductRefundsTable extends Migration
{
    /**
     * Run the migrations.
     */
    public function up()
    {
        Schema::create('product_refunds', function (Blueprint $table) {
            $table->id();
            $table->nullableMorphs('order', 'order');
            $table->unsignedBigInteger('user_id')->comment('用户id');
            $table->unsignedBigInteger('product_id')->comment('产品id');
            // 金额信息
            $table->decimal('amount', 12, 2)->comment('金额');
            $table->decimal('gold_amount', 12, 2)->default(0)->comment('KC通证');
            $table->decimal('burn', 12, 2)->default(0)->comment('燃烧KC通证');

            // 状态机控制
            $table->string('status')->default('draft')->index();
            $table->string('failure_reason', 500)->nullable();
            // 时间追踪
            $table->timestamp('requested_at')->nullable()->comment('请求时间');
            $table->timestamp('processed_at')->nullable()->comment('处理时间');
            $table->timestamp('completed_at')->nullable()->comment('完成时间');
            $table->timestamps();
        });
        \Illuminate\Support\Facades\DB::statement("ALTER TABLE `product_refunds` comment '产品退货'");
    }

    /**
     * Reverse the migrations.
     */
    public function down()
    {
        Schema::dropIfExists('product_refunds');
    }
}
